package com.feib.soeasy.service.impl;

import java.util.ArrayList;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.feib.soeasy.dao.UserLoginControlDao;
import com.feib.soeasy.model.User;
import com.feib.soeasy.model.UserLoginControl;
import com.feib.soeasy.pagination.PaginatedList;
import com.feib.soeasy.service.UserIdNotFoundException;
import com.feib.soeasy.service.UserLoginControlService;

/**
 * @title (#)UserLoginControlServiceImpl.java<br>
 * @description <br>
 * @author Anson Tsai<br>
 * @version 1.0.0 2010/11/25
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2010/12/5 create by Anson Tsai<br>
 */
@Service("userLoginControlService")
public class UserLoginControlServiceImpl extends BaseServiceImpl implements UserLoginControlService {

    @Resource(name = "userLoginControlDao")
    private UserLoginControlDao userLoginControlDao;

    /*
     * (non-Javdoc)
     * 
     * @see
     * com.feib.soeasy.service.UserLoginControlService#isDuplicateUserId(java
     * .lang.String, java.lang.String)
     */
    @Override
    public boolean isDuplicateUserId(String userId, String groupNo) {
        if (null != userLoginControlDao.findByUerIdGroupNo(userId, groupNo))
            return true;
        return false;
    }

    /*
     * (non-Javdoc)
     * 
     * @see
     * com.feib.soeasy.service.UserLoginControlService#queryByUerIdGroupNo(java
     * .lang.String, java.lang.String)
     */
    @Override
    public UserLoginControl queryByUerIdGroupNo(String userId, String groupNo) {
        return userLoginControlDao.findByUerIdGroupNo(userId, groupNo);
    }

    /*
     * (non-Javdoc)
     * 
     * @see
     * com.feib.soeasy.service.UserLoginControlService#enableUserLoginInfo(java
     * .lang.String, java.lang.String)
     */
    @Override
    public UserLoginControl enableUserLoginInfo(String userId, String groupNo) throws UserIdNotFoundException {
        UserLoginControl c = userLoginControlDao.findByUerIdGroupNo(userId, groupNo);
        if (null != c)
        {
            c.setActived(Boolean.TRUE);
            userLoginControlDao.save(c);
        }
        return c;
    }

    /*
     * (non-Javdoc)
     * 
     * @see
     * com.feib.soeasy.service.UserLoginControlService#disableUserLoginInfo(
     * java.lang.String, java.lang.String)
     */
    @Override
    public UserLoginControl disableUserLoginInfo(String userId, String groupNo) throws UserIdNotFoundException {
        UserLoginControl c = userLoginControlDao.findByUerIdGroupNo(userId, groupNo);
        if (null != c)
        {
            c.setActived(Boolean.FALSE);
            userLoginControlDao.save(c);
        }
        return c;
    }

    @Override
    public PaginatedList<UserLoginControl> queryEnabledInfoByUserIdGroupNo(String userId, String groupNo, boolean isBank, PaginatedList<UserLoginControl> paginationConfig) {
        return userLoginControlDao.queryEnabledInfoByUserIdGroupNo(userId, groupNo, isBank, paginationConfig);
    }

    @Override
    public void disableUserLoginInfo(ArrayList<UserLoginControl> userLoginInfos) {
        userLoginControlDao.disableUserLoginInfo(userLoginInfos);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.UserLoginControlService#findByUer(com.feib.soeasy.model.User)
     */
    @Override
    public UserLoginControl findByUer(User user) {
        return userLoginControlDao.findByUer(user);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.UserLoginControlService#save(com.feib.soeasy.model.UserLoginControl)
     */
    @Override
    public UserLoginControl save(UserLoginControl entity) {
        return userLoginControlDao.save(entity);
    }

}
